//
//  main.swift
//  swift
//
//  Created by 陈永红15180601024 on 2017/9/18.
//  Copyright © 2017年 Apple. All rights reserved.
//

import Foundation
extension NSString{
    func split(splitStr: NSString) -> [NSString]{
        var lastStr = self
        var res: [NSString] = []
        for _ in 0..<self.length{
            let strRange = lastStr.range(of: splitStr as String)
            if strRange.length != 0{
                let subStr = lastStr.substring(to: strRange.location)
                res.append(subStr as NSString)
                lastStr = lastStr.substring(from: strRange.location + splitStr.length) as NSString
            }
            else{
                res.append(lastStr)
                return removeNullValue(str: res)
            }
        }
        return []
    }
    func removeNullValue(str: [NSString]) -> [NSString]{
        var res: [NSString] = []
        for i in 0..<str.count{
            if str[i] != ""{
                res.append(str[i])
            }
        }
        return res
    }
    
}
var str = "swza"

print(str.split(splitStr: "s"))
print(str.split(splitStr: "w"))
print(str.split(splitStr: "z"))
print(str.split(splitStr: "a"))
